const gulp = require('gulp')
const addQueryFragment = require('gulp-add-query-fragment')
const config = require('./config');
const clean = require('gulp-clean');

gulp.task('clean', function () {
    console.log('清空旧有构建输出目标目录下的文件');
    return gulp.src(config.dist, { read: false })
        .pipe(clean());
});


gulp.task('addQueryFragment', ['clean'], function () {
    console.log('开始构建，添加版本');
    //Select the file or directory you want to operate
    gulp.src(config.src)
        .pipe(addQueryFragment([
            {
                //css selector
                selector: config.selector,

                //Add the query parameter to the href or src address of the  element selected by the css selector
                //such as './library/bootstrap/bootstrap.min.js' will be modified to
                //'./library/bootstrap/bootstrap.min.js?t=20170809&lang=chinese'
                query: config.query,
                overwrite: config.overwrite
            }
        ]))
        .pipe(gulp.dest(config.dist));
});

gulp.task('default', ['addQueryFragment'], function () {
    consoel.log('构建完成');
});